package com.chorye.swagger3.controller;

import com.chorye.swagger3.entity.Student;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

/**
 * @Company: 北京根网科技有限公司
 * @Author JiangYy
 * @Title: Swagger3Controller
 * @Description: Swagger3接口测试控制层
 * @Date 2019/1/8 14:05
 */
@RestController
@RequestMapping("/swagger3")
public class Swagger3Controller {

    /**
     * 无参测试
     *
     * @return 想说的话
     */
    @RequestMapping("/say_hello")
    public String sayHello() {
        return "hello, chorye!";
    }

    /**
     * 路径变量测试
     *
     * @param studentId 学生id
     * @return 学生实体类
     */
    @RequestMapping("/student/{studentId}")
    public Student path(@PathVariable Integer studentId) {
        Student student = new Student();
        student.setStudentId(studentId);
        student.setStudentName("chorye路径变量");
        student.setStudentBirth(new Date());
        student.setStudentCard(1234567990123L);
        student.setStudentScore(99.99);
        return student;
    }

    /**
     * 查询参数测试
     *
     * @param studentId 学生id
     * @return 学生实体类
     */
    @RequestMapping("/student")
    public Student query(Integer studentId) {
        Student student = new Student();
        student.setStudentId(studentId);
        student.setStudentName("chorye查询参数");
        student.setStudentBirth(new Date());
        student.setStudentCard(1234567990123L);
        student.setStudentScore(99.999);
        return student;
    }

    /**
     * Http头参数测试
     *
     * @param choryeHeaderId 自定义头信息
     * @return 自定义头信息
     */
    @RequestMapping("/header")
    public String header(@RequestHeader("chorye-header-ID") String choryeHeaderId) {
        return choryeHeaderId;
    }

    /**
     * 表单提交测试
     *
     * @param student 学生实体类
     * @return 学生实体类
     */
    @RequestMapping("/form")
    public Student form(Student student) {
        return student;
    }

    /**
     * json提交测试
     *
     * @param student 学生实体类
     * @return 学生实体类
     */
    @RequestMapping("/json")
    public Student json(@RequestBody Student student) {
        return student;
    }
}
